
define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/example/custScore/custScore.js'
], function (require, exports) {
  exports.ready = function (hashCode, data, cite) {
    // 注册该功能要用到的数据字典
    yufp.lookup.reg('DATA_STS,YESNO,SYS_TYPE');
    yufp.lookup.lookupMgr['TRANS_TYPE'] = [
      {key: '1', value: this.$t('custScore.zj')},
      {key: '2', value: this.$t('custScore.kj')}
    ];
    yufp.custom.vue({
      el: '#custScore',
      // 以m_开头的属性为UI数据不作为业务数据，否则为业务数据
      data: function () {
        var me = this;

        return {
          mainGrid: {
            currentRow: null,
            data: null,
            total: null,
            dataUrl: backend.scoreService + '/api/score/index',
            height: yufp.custom.viewSize().height - 140,
            queryFields: [
              {placeholder: this.$t('custScore.khbm'), field: 'custId', type: 'input'}
            ],
            queryButtons: [
              {
                label: this.$t('custScore.cx'),
                op: 'submit',
                type: 'primary',
                icon: 'search',
                click: function (model, valid) {
                  if (valid) {
                    var param = { condition: JSON.stringify(model) };
                    me.$refs.mytable.remoteData(param);
                  }
                }
              },
              {label: this.$t('custScore.zz'), op: 'reset', type: 'primary', icon: 'information'}
            ],
            paging: {
              page: 1,
              size: 10
            },
            tableColumns: [
              { label: this.$t('custScore.zhbh'), prop: 'accountNo', sortable: true, resizable: true },
              { label: this.$t('custScore.khbh'), prop: 'custId', sortable: 'custom', resizable: true },
              { label: this.$t('custScore.djjf'), prop: 'freezeAmt', sortable: true, resizable: true, align: 'right'},
              { label: this.$t('custScore.jf'), prop: 'amount', sortable: true, resizable: true, align: 'right'},
              { label: this.$t('custScore.ms'), prop: 'remark', sortable: true, resizable: true}

            ]
          },
          tradGrid: {
            dialogVisible: false,
            dataUrl: backend.scoreService + '/api/scoretrad/index',
            height: yufp.custom.viewSize().height - 140,
            tableColumns: [
              { label: this.$t('custScore.jysj'), prop: 'recordTime', sortable: true, resizable: true },
              { label: this.$t('custScore.khbh'), prop: 'custId', sortable: 'custom', resizable: true },
              { label: this.$t('custScore.zh'), prop: 'bankAcc', sortable: true, resizable: true},
              { label: this.$t('custScore.jfsl'), prop: 'realBalance', sortable: true, resizable: true, align: 'right'},
              { label: this.$t('custScore.jylx'), prop: 'transType', sortable: true, resizable: true, dataCode: 'TRANS_TYPE'}
              // { label: '交易渠道', prop: 'sericeCode',sortable: true, resizable: true},
            ]
          },
          totGrid: {
            dialogVisible: false,
            formDisabled: false,
            dataUrl: backend.scoreService + '/api/scoretot/index',
            height: yufp.custom.viewSize().height - 140,
            updateFields: [{
              columnCount: 2,
              fields: [
                { field: 'org', label: this.$t('custScore.jgdm')},
                { field: 'orgName', label: this.$t('custScore.jgmc')},
                { field: 'subject', label: this.$t('custScore.kmdm')},
                { field: 'subjectName', label: this.$t('custScore.kmmc')},
                { field: 'beginBalanceDr', label: this.$t('custScore.qcjfye')},
                { field: 'beginBalanceCr', label: this.$t('custScore.qcdfye')},
                { field: 'periodNetDr', label: this.$t('custScore.jffs')},
                { field: 'periodNetCr', label: this.$t('custScore.dffs')},
                { field: 'endBalanceDr', label: this.$t('custScore.jfye')},
                { field: 'endBalanceCr', label: this.$t('custScore.dfye')}

              ]
            }]
          },
          updateFields: [{
            columnCount: 2,
            fields: [
              { field: 'accountNo',
                label: this.$t('custScore.zhbh'),
                rules: [
                  {required: true, message: this.$t('custScore.btx'), trigger: 'blur'},
                  {max: 30, message: this.$t('custScore.srzgc'), trigger: 'blur'}]},
              { field: 'custId',
                label: this.$t('custScore.khbh'),
                rules: [
                  {required: true, message: this.$t('custScore.btx'), trigger: 'blur'},
                  {max: 30, message: this.$t('custScore.srzgc'), trigger: 'blur'}]},
              // { field: 'freezeAmt', label: this.$t('custScore.djjf'), rules: [
              //         {required: true, message: this.$t('custScore.btx'), trigger: 'change'}
              //     ] },
              // { field: 'amount',label: this.$t('custScore.jf'),  rules:[
              //        {required: true, message: this.$t('custScore.btx'), trigger: 'blur'}
              //    ]},
              { field: 'remark',
                label: this.$t('custScore.ms'),
                rules: [
                  {required: true, message: this.$t('custScore.btx'), trigger: 'blur'}
                ]}
            ]
          }],
          dataParams: {},
          formDisabled: false,
          dialogFormVisible: false,
          dialogStatus: false,
          textMap: {
            update: this.$t('custScore.xg'),
            create: this.$t('custScore.xz'),
            trad: this.$t('custScore.ls'),
            tot: this.$t('custScore.nbz')
          }
        };
      },
      mounted: function () {
      },
      methods: {
        rowClickFn: function (row, index) {
          this.mainGrid.currentRow = this.$refs.mytable.selections[0];
        },
        queryMainGridFn: function () {
          var me = this;
          me.$refs.mytable.remoteData();
        },
        openCreateFn: function () {
          this.dialogStatus = 'create';

          this.dialogFormVisible = true;
          this.formDisabled = false;
          this.$nextTick(function () {
            this.$refs.myform.resetFields();
          });
        },
        openEditFn: function (row) {
          this.dialogStatus = 'update';
          this.dialogFormVisible = true;
          this.formDisabled = false;

          this.$nextTick(function () {
            this.$refs.myform.resetFields();
            yufp.extend(this.$refs.myform.formModel, row);
          });
        },
        saveCreateFn: function (formName) {
          var vue = this;
          var myform = vue.$refs.myform;
          var formFlag = true;

          myform.validate(function (valid) {
            formFlag = valid;
          });

          if (formFlag) {
            var comitData = {
            };
            yufp.extend(comitData, myform.formModel);

            yufp.service.request({
              method: 'POST',
              url: backend.scoreService + '/api/score/create',
              data: comitData,
              callback: function (code, message, response) {
                if (response.code === '0') {
                  vue.dialogFormVisible = false;
                  vue.$message({message: this.$t('custScore.jfkhcg'), type: 'info'});
                  vue.queryMainGridFn();
                } else {
                  vue.$message({message: response.message, type: response.level});
                }
              }
            });
          } else {
            this.$message({message: this.$t('custScore.qjcsrxsfhf'), type: 'warning'});
            return false;
          }
        },
        saveEditFn: function (formName) {
          var vue = this;
          var myform = vue.$refs.myform;
          var formFlag = true;
          myform.validate(function (valid) {
            formFlag = valid;
          });
          if (!formFlag) {
            this.$message({message: this.$t('custScore.qjcsrxsfhf'), type: 'warning'});
            return false;
          }

          var comitData = {
          };

          yufp.extend(comitData, myform.formModel);

          yufp.service.request({
            method: 'POST',
            url: backend.scoreService + '/api/score/update',
            data: comitData,
            callback: function (code, message, response) {
              if (response.code === '0') {
                vue.dialogFormVisible = false;
                vue.$message({message: vue.$t('custScore.sjbccg')});
                vue.queryMainGridFn();
              } else {
                vue.$message({message: response.message, type: response.level});
              }
            }
          });
        },
        handleModify: function (status) {
          var row;
          if (this.$refs.mytable.selections.length !== 1) {
            this.$message({message: this.$t('custScore.qxzytsj'), type: 'warning'});
            return;
          } else {
            row = this.$refs.mytable.selections[0];
          }
          if (status === 'edit') {
            this.mainGrid.currentRow = row;
            this.openEditFn(row);
          } else if (status === 'trad') {
            this.mainGrid.currentRow = row;
            this.openTradFn(row);
          } else if (status === 'tot') {
            this.openTotFn();
          }
        },
        openTradFn: function (row) {
          this.dialogStatus = 'trad';
          this.tradGrid.dialogVisible = true;
          this.tradGrid.dataUrl = backend.scoreService + '/api/scoretrad/index?custId=' + row.custId;

          var me = this;
          this.$nextTick(function () {
            me.$refs.mytableTrad.remoteData();
          });
        },
        openTotFn: function () {
          var me = this;
          this.dialogStatus = 'tot';
          this.totGrid.dialogVisible = true;
          this.totGrid.formDisabled = true;

          this.$nextTick(function () {
            yufp.service.request({
              method: 'GET',
              url: backend.scoreService + '/api/scoretot/index',
              data: null,
              callback: function (code, message, response) {
                if (response.code === '0') {
                  me.dialogFormVisible = false;
                  yufp.extend(me.$refs.myformTot.formModel, response.data[0]);
                } else {
                  me.$message({message: response.message, type: response.level});
                }
              }
            });
          });
        }
      }
    });
  };

  // 消息处理
  exports.onmessage = function (type, message) { };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {};
});
